import utils
import cv2
import numpy as np
import mycv


def read_yuv(path, w, h):
    yuv = np.zeros((h, w, 3), dtype=np.uint8)
    u = np.zeros((int(h / 2), int(w / 2)), dtype=np.uint8)
    v = np.zeros((int(h / 2), int(w / 2)), dtype=np.uint8)
    with open(path, 'rb') as f:
        for row in range(h):
            for col in range(w):
                yuv[row, col, 0] = int(f.read(1).hex(), 16)
        for row in range(int(h / 2)):
            for col in range(int(w / 2)):
                u[row, col] = int(f.read(1).hex(), 16)
                v[row, col] = int(f.read(1).hex(), 16)

    yuv[:, :, 1] = cv2.resize(u, (w, h))
    yuv[:, :, 2] = cv2.resize(v, (w, h))
    return yuv

p = r'/media/fang/3441-913C/img/tsr/not_in_center_00000.yuv420sp'
yuv = read_yuv(p, 600, 300)
bgr1 = cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR)
# bgr2 = mycv.myYUV2BGR(yuv)

hsv1 = cv2.cvtColor(bgr1, cv2.COLOR_BGR2HSV)
hsv2 = mycv.myBGR2HSV(bgr1)

bgr2 = cv2.cvtColor(hsv2, cv2.COLOR_HSV2BGR)

print("aa")
cv2.imshow('1', bgr1)
cv2.imshow('2', bgr2)
cv2.waitKey(0)

print("aa")